﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Areas/Manage/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<QianBuo.Lottery.Web.Areas.Manage.Models.Lottery.WinMoneySetModel>" %>
<%@ Import Namespace="Code.Models" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    奖金设置
</asp:Content>

<asp:Content ContentPlaceHolderID="StyleAndScript" runat="server" ID="Content3">
    <style type="text/css">
        .table td ,.table th { padding:3px 0px}
        input[type='checkbox']{ margin:1px;}
        .validation_summary_div ul{ float:left; overflow:hidden; height:auto;}
        .validation_summary_div li{ float:left; overflow:hidden; height:auto; width:235px; line-height:21px;  text-align:left;
        list-style-type:decimal; list-style-position:inside; font-weight:normal; font-family:Arial; font-size:12px;}
    </style>
    <script src='<%=Url.Content("~/Scripts/jquery.metadata.js") %>' type="text/javascript"></script>
    <script type="text/javascript">
        function ddlChage(o) {
            var url = '<%=Url.Action("ConfigWinMoney","Lottery", new { id="_id_"})%>';
            document.location.href = url.replace('_id_', o.value);
        }
        $(document).ready(function () {
            var str = null;
            $("#optionform").validate();
            $("input[ckmodelid]").click(function () {
                var item = this;
                var ckmodelid = $(this).attr("ckmodelid");
                $("." + ckmodelid + " :checkbox").each(function () {
                    this.checked = item.checked;
                });
            });
            $("input[modelid]").change(function () {
                var item = $(this);
                var modelid = item.attr("modelid");
                var backMoneyType = _ParseInt(item.attr("backMoneyType"));
                var num = _ParseDouble(this.value);
                if (num == null || num < 0)
                    return;
                else {
                    $("." + modelid + " :text").each(function () {
                        if (backMoneyType != null) {
                            var _backMoneyType = _ParseInt($(this).attr("backMoneyType"));
                            
                            if(backMoneyType == _backMoneyType)
                                this.value = num;
                        } else {
                            var tp = _ParseDouble($(this).attr("oldvalue"));
                            str = num.div(100).mul(tp);
                            this.value = str;
                        }
                        $(this).valid();
                    });
                }
            }).keypress(function (e) {
                if (e.keyCode == 13) {
                    e.keyCode = 9;
                    this.blur();
                    return false;
                }
            });
        });
    </script>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    
    <div>
        <% Html.DisableClientValidation(); %>
        <% Html.BeginForm(new { id = "optionform" }, new {lottery=Model.LotteryID }); %>
        <fieldset>
            <legend>奖金设置</legend>
            <%
                var groupwin = Model.Options.GroupBy(p => new { Name=p.WinMoneyName ,ID=p.Option.WinMoneyModelID});
                var backMoneyTypes = Model.Options.GroupBy(p => new {ID = p.Option.BackMoneyTypeID, Name = p.PlayNames}, (k, p) => k);
            %>
            <%=Html.DropDownListFor(p => p.LotteryID, Model.Lotterys.Select(p => new SelectListItem { Text = p.Value, Value =p.Key.ToString(), Selected = Model.LotteryID.HasValue ? p.Key == Model.LotteryID : false }), new { onchange = "ddlChage(this)" })%>
            <table class="table" width="100%">
            <% foreach (var gitem in groupwin) %>
            <% { %>
                <tr>
                    <th><%=gitem.Key.Name%>模式</th>
                    <th align="left">
                        <input type="checkbox" title="全选" ckmodelid='<%=gitem.Key.ID %>WinMoney'/><label>奖金<input type="text" class="text40" value="100" modelid='<%=gitem.Key.ID %>WinMoney' validate = "{number:true,min:0,messages:{number:'*',min:'>=0'}}" />%</label>
                    </th>
                    <th align="left">
                        <input type="checkbox" title="全选" ckmodelid='<%=gitem.Key.ID %>BackMoney'/><label>返点<input type="text" class="text40" value="100" modelid='<%=gitem.Key.ID %>BackMoney' validate="{number:true,min:0,messages:{number:'*',min:'>=0'}}" />%</label>
                    </th>
                    <th align="left" title="每1%的返点转换成奖金的换算率">
                        <label>返点加奖换算比率<input type="text" class="text40" value="100" modelid='<%=gitem.Key.ID %>BackMoneyToWinMoney' validate = "{number:true,min:0,messages:{number:'*',min:'>=0'}}" />%</label>
                    </th>
                    <th align="left" title="最多可调返点">
                        <label>最大返点加奖点数<input type="text" class="text40" value="100" modelid='<%=gitem.Key.ID %>MaxBackMoneyToWinMoney' validate="{number:true,min:0,messages:{number:'*',min:'>=0'}}" />%</label>
                    </th>
                </tr>
                <% foreach (var item in gitem)%>
                <% { %>                
                <% var i = Array.FindIndex(Model.Options, p => p == item); %>
                <tr>
                    <td align="right">
                        <%=item.PlayName%>
                    </td>
                    <td class='<%=gitem.Key.ID %>WinMoney' align="left">
                        <%=Html.CheckBoxFor(p => p.Options[i].Option.ResetWinMoney, new { title = "重置所有用户" })%>
                        <%=Html.TextBoxFor(p => p.Options[i].Option.WinMoney, new { @class = "text50", playtype = item.Option.PlayTypeListID, backMoneyType = item.Option.BackMoneyTypeID, oldvalue = item.Option.WinMoney, validate = "{required:true,number:true,min:0,max:999999999,messages:{required:'',number:'',min:'>=0',max:'<=999999999'}}" })%>
                        <%=Html.ValidationMessageFor(p => p.Options[i].Option.WinMoney)%>
                    </td>
                    <td class='<%=gitem.Key.ID %>BackMoney' align="left">
                        <%=Html.CheckBoxFor(p => p.Options[i].Option.ResetBackMoneyRatio, new { title = "重置所有用户" })%>
                        <%=Html.TextBoxFor(p => p.Options[i].Option.BackMoneyRatio, new { @class = "text50", playtype = item.Option.PlayTypeListID, backMoneyType = item.Option.BackMoneyTypeID, oldvalue = item.Option.BackMoneyRatio, validate = "{required:true,number:true,min:0,max:999999999,messages:{required:'',number:'',min:'>=0',max:'<=999999999'}}" })%>%
                        <%=Html.ValidationMessageFor(p => p.Options[i].Option.BackMoneyRatio)%>
                    </td>
                    <td class='<%=gitem.Key.ID %>BackMoneyToWinMoney' align="left">
                        1：<%=Html.TextBoxFor(p => p.Options[i].Option.BackMoneyToWinMoneyRatio, new { @class = "text50", playtype = item.Option.PlayTypeListID, backMoneyType = item.Option.BackMoneyTypeID, oldvalue = item.Option.BackMoneyToWinMoneyRatio, validate = "{required:true,number:true,min:0,max:999999999,messages:{required:'',number:'',min:'>=0',max:'<=999999999'}}" })%>
                        <%=Html.ValidationMessageFor(p => p.Options[i].Option.BackMoneyToWinMoneyRatio)%>
                    </td>
                    <td class='<%=gitem.Key.ID %>MaxBackMoneyToWinMoney' align="left">
                        <%=Html.TextBoxFor(p => p.Options[i].Option.MaxBackMoneyToWinMoney, new { @class = "text50", playtype = item.Option.PlayTypeListID, backMoneyType = item.Option.BackMoneyTypeID, oldvalue = item.Option.MaxBackMoneyToWinMoney, validate = "{required:true,number:true,min:0,max:999999999,messages:{required:'',number:'',min:'>=0',max:'<=999999999'}}" })%>%
                        <%=Html.ValidationMessageFor(p => p.Options[i].Option.MaxBackMoneyToWinMoney)%>
                    </td>
                </tr>
                <% } %>
                <% foreach (var item in backMoneyTypes) %>
                <% { %>
                <tr>
                    <td>&nbsp;</td>
                    <td align="right"><%=item.Name %>：</td>
                    <td align="left">
                        <input type="text" class="text50" backMoneyType="<%=item.ID %>" modelid="<%=gitem.Key.ID + "BackMoney" %>" validate="{number:true,min:0,messages:{number:'*',min:'>=0'}}" />
                    </td>
                    <td align="left">
                        <input type="text" class="text50" backMoneyType="<%=item.ID %>" modelid="<%=gitem.Key.ID + "BackMoneyToWinMoney" %>" validate="{number:true,min:0,messages:{number:'*',min:'>=0'}}" />
                    </td>
                    <td align="left">
                        <input type="text" class="text50" backMoneyType="<%=item.ID %>" modelid="<%=gitem.Key.ID + "MaxBackMoneyToWinMoney" %>" validate="{number:true,min:0,messages:{number:'*',min:'>=0'}}" />
                    </td>
                </tr>
                <% } %>
            <% } %>
                <tr>
                    <td colspan="7">
                        <input type="submit" value="保存" onclick="return confirm('确定提交吗？')" />&nbsp;&nbsp;
                        <input type="reset" value="重设" />
                    </td>
                </tr>
            </table>
        </fieldset>
        <%=Html.SerializableFor(p => p.ViewData) %>
        <%=Html.SerializableFor(p=>p.Lotterys) %>
        <%Html.EndForm(); %>
    </div>
</asp:Content>
